/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.arg.deploy.webapp.common;

import java.util.List;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.Comboitem;

/**
 *
 * @author sorasaks
 */
public class ComboboxUtil {

    public static void buildCombobox(Combobox cbb, List<String> object, String defaultItem) {
        cbb.getItems().clear();
        int selectedIndex = 0, idx = 0;
        if (object != null && !object.isEmpty()) {
            for (String s : object) {
                Comboitem item = new Comboitem();
                item.setLabel(s);
                item.setValue(s);
                
                if(s.equalsIgnoreCase(defaultItem)) {
                    selectedIndex = idx;
                }
                idx++;
                
                cbb.appendChild(item);
            }

            cbb.setSelectedIndex(selectedIndex);
        }
    }
}
